package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func main() {
	ah := make(chan struct{})
	bh := make(chan struct{})
	ch := make(chan struct{})
	wg.Add(3)

	go a1(ah, bh)
	go b1(bh, ch)
	go c1(ch, ah)
	ah <- struct{}{}
	wg.Wait()
}
func a1(ch chan struct{}, bh chan struct{}) {
	defer wg.Done()
	for i := 0; i < 10; i++ {
		<-ch
		fmt.Println("a")
		bh <- struct{}{}
	}
	<-ch
	close(bh)
}
func b1(bh chan struct{}, ch chan struct{}) {
	defer wg.Done()
	for range bh {
		fmt.Println("b")
		ch <- struct{}{}
	}
	close(ch)
}
func c1(ch chan struct{}, ah chan struct{}) {
	defer wg.Done()
	for range ch {
		fmt.Println("c")
		ah <- struct{}{}
	}
}
